import json
from flask import Flask, jsonify,Response

from pathlib import Path
import pandas as pd

csv_path = Path(__file__).parent / 'train.csv'

data = pd.read_csv(csv_path)
# data.to_json('train.json', orient='records', force_ascii=False, indent=2) #输出json

# result = []
# for line in data.strip().splitlines():
#     edu, exp, salary = line.split(',')
#     result.append({
#         "学历": edu,
#         "工作经验": int(exp),
#         "工资": int(salary)
#     })


# 转换为清晰美观的 JSON 字符串（含中文、换行格式）
json_obj = data.to_dict(orient='records')
json_str = json.dumps(json_obj, ensure_ascii=False, indent=2)



app = Flask(__name__)

@app.route('/')
def book_list():
    # return jsonify({
    #     "code": 0,
    #     "message": "success",
    #     "data": json.loads(json_str)
    # })
    return Response(json_str, content_type='application/json; charset=utf-8')

if __name__ == '__main__':
    app.run(debug=True)